﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>TreeView - Data Binding</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" href="../../../css/samples.css" />
    <link rel="stylesheet" href="../../../css/integralui.css" />
    <link rel="stylesheet" href="../../../css/integralui.treeview.css" />
    <link rel="stylesheet" href="../../../css/themes/theme-flat-blue.css" />
    <script type="text/javascript" src="../../../external/angular.min.js"></script>
    <script type="text/javascript" src="../../../js/angular.integralui.min.js"></script>
    <script type="text/javascript" src="../../../js/angular.integralui.lists.min.js"></script>
    <script type="text/javascript" src="../../../js/angular.integralui.treeview.min.js"></script>
    <script type="text/javascript">
 		angular
			.module("appModule", ["integralui"])
			.controller("appCtrl", ["$scope", "$timeout", "IntegralUITreeViewService", function($scope, $timeout, $treeService){
				$scope.treeName = "treeSample";
				$scope.itemIcon = "icons-medium empty-doc";
				$scope.items = [];

				$scope.dataSource = [
					{ 
						directoryID: 1,
						directory: "Favorites",
						directoryIcon: "icons-medium favorites",
						children: [
							{ directoryID: 11, parentID: 1, directory: "Desktop" },
							{ directoryID: 12, parentID: 1, directory: "Downloads", directoryIcon: "icons-medium downloads" }
						]
					},
					{ 
						directoryID: 2,
						directory: "Libraries",
						directoryIcon: "icons-medium folder",
						children: [
							{ 
								directoryID: 21, 
								parentID: 2, 
								directory: "Documents", 
								directoryIcon: "icons-medium documents",
								isExpanded: false,
								children: [
									{ directoryID: 211, parentID: 21, directory: "My Documents" },
									{ directoryID: 212, parentID: 21, directory: "Public Documents" }
								]
							},
							{ directoryID: 22, parentID: 2, directory: "Music", directoryIcon: "icons-medium music-note" },
							{ directoryID: 23, parentID: 2, directory: "Pictures" },
							{ directoryID: 24, parentID: 2, directory: "Videos", directoryIcon: "icons-medium videos" }
						]
					},
					{ 
						directoryID: 3,
						directory: "Computer",
						directoryIcon: "icons-medium pc",
						isExpanded: false,
						children: [
							{ directoryID: 31, parentID: 3, directory: "Local Disk (C:)" },
							{ directoryID: 32, parentID: 3, directory: "Storage (D:)" }
						]
					},
					{ directoryID: 4, directory: "Network", directoryIcon: "icons-medium network" },
					{ directoryID: 5, directory: "Recycle Bin", directoryIcon: "icons-medium recycle" }
				];

				$scope.dataFields = {
					expanded: 'isExpanded',
					icon: 'directoryIcon',
					id: 'directoryID',
					items: 'children',
					pid: 'parentID',
					text: 'directory'
				}

				var initTimer = $timeout(function(){
					$treeService.loadData($scope.treeName, $scope.dataSource, null, $scope.dataFields, false);
					$treeService.selectedItem($scope.treeName, $treeService.findItemById($scope.treeName, 3));

					$timeout.cancel(initTimer);
				}, 1);

			}]);
    </script>
    <style type="text/css">
		.iui-treeview-item-content
		{
			padding: 4px;
		}
    </style>
</head>
<body>
	<div class="header">
        <div class="header-content">
		    <h1><span style="color:#c60d0d">IntegralUI</span> Studio <span style="font-size:0.75em; font-style:italic">for Web</span></h1>
        </div>
        <hr class="head-separator" />
    </div>
    <div class="content" ng-app="appModule">
        <div class="feature" ng-controller="appCtrl">
	        <h2 class="feature-title">TreeView / Data Binding</h2>
	        <div class="feature-content">
                <iui-treeview name="{{treeName}}" class="directive" items="items" item-icon="itemIcon"></iui-treeview>
                <br style="clear:both;"/>
                <div class="feature-help">
                    <p><span class="initial-space"></span>In this sample we are using an arbitrary data source to load the content of TreeView. In order this to work, you need to match the data fields from your data source to the fields of item objects. You can use any custom names for your data, as long as you match those names with object fields, the TreeView will be populated.</p>
                    <p><span class="initial-space"></span>For purpose of data binding, we are using the <strong>dataFields</strong> attribute which accepts an object containing all names for the data fields (this property can also be used as parameter in <span class="code-func">loadData</span> method, as it is in this example case). This property allows you to link fields from your data source to the fields of item objects in the TreeView.</p>
                    <p><span class="initial-space"></span>Default settings for this property are:</p>
                    <div class="code-block">
                    	<p class="code-line"><span class="code-var">dataFields</span> = {</p>
                        <div style="padding-left:30px">
							<p class="code-line">allowDrag: <span class="code-string">'allowDrag'</span>,</p>
							<p class="code-line">allowDrop: <span class="code-string">'allowDrop'</span>,</p>
							<p class="code-line">allowEdit: <span class="code-string">'allowEdit'</span>,</p>
							<p class="code-line">allowFocus: <span class="code-string">'allowFocus'</span>,</p>
							<p class="code-line">autoCheck: <span class="code-string">'autoCheck'</span>,</p>
							<p class="code-line">checkBoxSettings: <span class="code-string">'checkBoxSettings'</span>,</p>
							<p class="code-line">checked: <span class="code-string">'checked'</span>,</p>
							<p class="code-line">checkState: <span class="code-string">'checkState'</span>,</p>
							<p class="code-line">content: <span class="code-string">'content'</span>,</p>
							<p class="code-line">contextMenu: <span class="code-string">'contextMenu'</span>,</p>
							<p class="code-line">enabled: <span class="code-string">'enabled'</span>,</p>
			                <p class="code-line">expanded: <span class="code-string">'expanded'</span>,</p>
							<p class="code-line">hasChildren: <span class="code-string">'hasChildren'</span>,</p>
			                <p class="code-line">icon: <span class="code-string">'icon'</span>,</p>
			                <p class="code-line">id : <span class="code-string">'id'</span>,</p>
							<p class="code-line">items: <span class="code-string">'items'</span>,</p>
			                <p class="code-line">pid : <span class="code-string">'pid'</span>,</p>
			                <p class="code-line">statusIcon: <span class="code-string">'statusIcon'</span>,</p>
			                <p class="code-line">style: <span class="code-string">'style'</span>,</p>
			                <p class="code-line">text : <span class="code-string">'text'</span>,</p>
			                <p class="code-line">value: <span class="code-string">'value'</span></p>
		                </div>
				        <p class="code-line">}</p>
	                </div>
                    <p style="padding-bottom:30px"><span class="initial-space"></span>For more information check out the source code of this sample.</p>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
